package com.heima.admin.job;

import com.heima.admin.service.WemediaNewsAutoScanService;
import com.heima.feigns.WemediaFeign;
import com.heima.model.common.dtos.ResponseResult;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class WeMediaNewsAutoScanJob {
    @Autowired
    WemediaNewsAutoScanService wemediaNewsAutoScanService;

    @Autowired
    WemediaFeign wemediaFeign;


    @XxlJob("weMediaNewsAutoScanJob")
    public ReturnT<String> autoScanJob(String param) {
        ResponseResult<List<Integer>> release = wemediaFeign.findRelease();

        log.info("自媒体文章审核调度任务开始执行...");
        if (release.getCode().intValue() != 0) {
            log.error("定时调度任务执行失败 ===================> " + release.getErrorMessage());
            return ReturnT.FAIL;
        }
        List<Integer> newsIds = release.getData();

        if (newsIds != null && !newsIds.isEmpty()) {
            for (Integer newsId : newsIds) {
                wemediaNewsAutoScanService.autoScanByMediaNewsId(newsId);
            }
        }
        log.info("自媒体文章审核调度任务执行结束....");
         return  ReturnT.SUCCESS;

    }
}
